/* 
 *  Syntelos XB
 *  Copyright (C) 2006 John Pritchard.
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License as
 *  published by the Free Software Foundation; either version 2 of
 *  the License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
 *  02111-1307 USA
 */

package syntelos.xb.at;

/** 
 * 
 * 
 * @author jdp
 */
public final class SourceDebugExtension 
    extends syntelos.xb.Attribute
{
    public final static java.lang.String ATNAME = "SourceDebugExtension";
    public final static syntelos.iou.dom.Name NAME = new syntelos.iou.dom.impl.Name(ELEMENT_NODE,"http://www.syntelos.org/xb/at","xat:source-debug-extension");

    public SourceDebugExtension(org.w3c.dom.Document doc, syntelos.iou.dom.Name name){
        super(doc,name);
    }
    public SourceDebugExtension(org.w3c.dom.Document doc){
        this(doc,NAME);
    }
    public SourceDebugExtension(){
        this(DOC_NIL);
    }

    public syntelos.iou.dom.Node compile(){
        /*
         * Write CF into base64 CF
         */
        //throw new syntelos.xb.Error.Bug("TODO (write base64 CF)");

        return this;
    }
    public syntelos.iou.dom.Node decompile(){
        /*
         * Read base64 child-text into CF
         */
        //throw new syntelos.xb.Error.Bug("TODO (read base64 CF)");

        return this;
    }
    public int atlen(){
        byte[] cf = this.getCF();
        int cf_len = (null == cf)?(0):(cf.length);
        return (4 + cf_len);
    }
    public void readCF(syntelos.xb.IO.Uri src, syntelos.xb.CF.Reader reader)
        throws java.io.IOException
    {
        int cf_len = reader.readInt();
        byte[] cf = null;
        if (0 < cf_len){
            cf = new byte[cf_len];
            reader.readFully(cf,0,cf_len);
        }
        this.setCF(cf);
    }
    public void writeCF(syntelos.xb.IO.Uri dst, syntelos.xb.CF.Writer writer)
        throws java.io.IOException
    {
        this.getAttributeName().writeCF(dst,writer);
        //
        byte[] cf = this.getCF();
        int cf_len = (null == cf)?(0):(cf.length);
        writer.writeInt(cf_len);
        if (0 < cf_len)
            writer.write(cf,0,cf_len);
    }
}
